#include "leak_test.h"
#include "ui_leak_test.h"
#include "main.h"

leak_test::leak_test(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::leak_test)
{
    ui->setupUi(this);
    ui->pressure_display->setpressure_display();
    timer=new QTimer();
    QObject:: connect( timer, SIGNAL(timeout()), SLOT(timeDone()) );
    connect( controller, SIGNAL(leak_test_timer_on()), SLOT(timer_start()) );
    timer->start(1000);
}

leak_test::~leak_test()
{
    delete ui;
}

void leak_test::timeDone()
{
  //  if(!timer_working) {ui->test_time->countdown(899);timer_working=1;}
    if(door_closed_OK)
    {
        ui->door_operation_btn->setText(trUtf8("关门"));
        ui->door_operation_btn->SET_COLOR_GREEN
    }
    else
    {ui->door_operation_btn->setText(trUtf8("门未关"));
     ui->door_operation_btn->SET_COLOR_RED}

    if(!sterilizing && ui->startorstop_btn->text()==trUtf8("停止")) {
        ui->startorstop_btn->setChecked(false);
        ui->startorstop_btn->setText(trUtf8("开始"));
        ui->startorstop_btn->SET_COLOR_GREEN
        ui->test_time->stop();
          LEDB_ON
        }

    if(air_supply_valve_isopen)
   {
   ui->air_back_btn->setText(trUtf8("正在回气"));
   ui->air_back_btn->SET_COLOR_GREEN
    }
    else
    {
        ui->air_back_btn->setText(trUtf8("回气"));
        ui->air_back_btn->SET_COLOR_GRAY
    }

}

void leak_test::on_startorstop_btn_clicked()
{
    BUTTON_SOUND;
   if(door_closed_OK)
 {
    if(ui->startorstop_btn->isChecked())
   {
    sterilization_protype = LEAK_TEST_PROTYPE;
    controller->start();
    ui->startorstop_btn->setText(trUtf8("停止"));
    ui->startorstop_btn->SET_COLOR_RED
    STOP_AUTO_HEAT
    LEDA_ON
    LEDB_OFF
    }
    else{
         STOP_CMD
        ui->test_time->clear();
        ui->startorstop_btn->setText(trUtf8("开始"));
        ui->startorstop_btn->SET_COLOR_GREEN
        LEDA_OFF
    }
  }
   else WARN->show_sound("门未关！");
}

void leak_test::on_air_back_btn_clicked()
{
    BUTTON_SOUND;
  if(ui->air_back_btn->isChecked())
  {
     air_supply_valve_ON;
     ui->air_back_btn->SET_COLOR_RED
  }
  else {
      air_supply_valve_OFF;
      ui->air_back_btn->SET_COLOR_GREEN
       }

}

void leak_test::on_return_btn_clicked()
{
   BUTTON_SOUND;
   //manager->showFullScreen();
   if(air_supply_valve_isopen)
  {
     air_supply_valve_OFF
   }
   this->close();
}

void leak_test::on_door_operation_btn_clicked()
{
    BUTTON_SOUND;
   door_operation->enter();
}
void leak_test::timer_start()
{
 ui->test_time->countdown(1200);
}
